<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        body {
            background-color: #f7f8fa;
        }

        .charts-container {
            display: grid;
            gap: 10px;
            grid-template-columns: 1fr 1fr 1fr;
        }
        .charts-item {
            background-color: #fff;
        }
    </style>
    <!-- 引入刚刚下载的 ECharts 文件 -->
    <!--    <script src="echarts.js"></script>-->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/echarts/5.5.0/echarts.min.js"></script>
    <!-- 为 ECharts 准备一个定义了宽高的 DOM -->
    <div class="charts-container">
        <div class="charts-item" id="main" style="width: 100%;height:400px;"></div>
        <div class="charts-item" id="main2" style="width: 100%;height:400px;"></div>
        <div class="charts-item" id="main3" style="width: 100%;height:400px;"></div>
    </div>
    <script type="text/javascript">
        function drawChart1(xData,yData){
            // 基于准备好的dom，初始化echarts实例
            var myChart = echarts.init(document.getElementById('main'));
            // 指定图表的配置项和数据
            var option = {
                title: {
                    text: '员工部门分布'
                },
                tooltip: {},
                legend: {
                    data: ['部门人数']
                },
                xAxis: {
                    data: xData
                },
                yAxis: {},
                series: [
                    {
                        name: '部门',
                        type: 'bar',
                        data: yData
                    }
                ]
            };
            // 使用刚指定的配置项和数据显示图表。
            myChart.setOption(option);
        }
        //绘制饼图
        function drawChart2(data) {
            var myChart = echarts.init(document.getElementById('main2'));
            option = {
                title: {
                    text: '员工性别比例',
                    left: 'center'
                },
                tooltip: {
                    trigger: 'item'
                },
                legend: {
                    orient: 'vertical',
                    left: 'left'
                },
                series: [
                    {
                        name: '性别',
                        type: 'pie',
                        radius: '50%',
                        data: data,
                        emphasis: {
                            itemStyle: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            };
            myChart.setOption(option);
        }
        //绘制折线图
        function drawChart3(xData,yData) {
            var myChart = echarts.init(document.getElementById('main3'));
            option = {
                title: {
                    text: '员工薪资图',
                    textStyle:{
                        color:'red',
                    },
                    padding:10,
                    left:210,
                },
                xAxis: {
                    type: 'category',
                    data: xData
                },
                yAxis: {
                    type: 'value'
                },
                series: [
                    {
                        data: yData,
                        type: 'line'
                    }
                ]
            };
            myChart.setOption(option);
        }
    </script>
</head>
<body>
</body>
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript">
    //页面准备完毕，开始请求数据，画图
    $(function (){
        $.ajax({
            url:"../php/emp.php",
            success: function (res){
                console.log(res);
                drawChart1(res.data.xData,res.data.yData);
            },
            error:function (){
                alert("请求失败");
            }
        });
    });
    $.ajax({
        url:"../php/emp_sex.php",
        success: function (res){
            drawChart2(res.data);
        },
        error:function (){
            alert("请求失败");
        }
    });
    $.ajax({
        url:"../php/emp_salary.php",
        success: function (res){
            console.log(res);
            drawChart3(res.data.xData,res.data.yData);
        },
        error:function (){
            alert("请求失败");
        }
    });
</script>
</html>
